import 'babel-polyfill';
import * as Koa from 'koa';
import { resolve } from 'path';
import * as R from 'ramda';
import conf from './config/index'
// import './middlewares/database'

const r = (path:string) => resolve(__dirname, path);
const host = conf.HOST;
const port = conf.PORT;
const MIDDLEWARES = ['general', 'router'];//'database',

class Server {
  private app:Koa;
  constructor() {
    this.app = new Koa();
    this.useMiddleWares(this.app)(MIDDLEWARES)
  }

  useMiddleWares(app:Koa) {
    return R.map(R.compose(
      R.map((i:any) => i(app)),
      require,
      (i:string) => `${r('./middlewares')}/${i}`
    ))
  }

  async start() {
    this.app.listen(port, host)
    console.log('Server listening on ' + host + ':' + port)
  }
}

const app = new Server()

app.start()

// const app = new Koa();
// const router = new Router();

// router.get('/*', async (ctx) => {
//     ctx.body = 'Hello World!';
// });

// app.use(router.routes());

// app.listen(3000);

// console.log('Server running on port 3000');
